//	KademliaMain.h : 
//
#pragma once
#include "dataprovider.h"

#include "Windows.h"
#include "GradeIface.h"

#include <string>

namespace gKad {

	class DataProvider;

	class KademliaMain {
	public:
		KademliaMain();

		void Execute();
		static KademliaMain *GetInstance();
		void WriteLog(string);
		void SetIAppAPI(IAppAPI *);
		void SetHModule(HMODULE);

		TGradeAddr	GetServerAddr();
		HMODULE		GetServerHmodule();
		IAppAPI		*GetServerIApi();
		TAppID		*GetServerId();

	protected:
		HANDLE			waitEvent;
		DataProvider	*dataProvider;

	private:
		IAppAPI			*iApi;
		ILogger			*logger;
		TGradeAddr		serverAddr;
		TAppID			serverId;
		HMODULE			moduleHandle;

		// Initializes all components
		//
		void Init();

		// Note that the next two functions are not given bodies, thus any attempt 
		// to call them implicitly will return as compiler errors. This prevents 
		// accidental copying of the only instance of the class.
		KademliaMain(const KademliaMain &old); // disallow copy constructor
		const KademliaMain &operator=(const KademliaMain &old); //disallow assignment operator
		~KademliaMain();

		void getDestAndFileName(struct file_request *);
	};
}